Skip to content

fix(spp_vocabulary): support extra domain for vocabulary_code search of the same display name#82

Merged
gonzalesedwin1123 merged 1 commit into19.0from
fix/disambiguate-vocab-by-extra-domain
Mar 10, 2026
Merged

fix(spp_vocabulary): support extra domain for vocabulary_code search of the same display name#82
gonzalesedwin1123 merged 1 commit into19.0from
fix/disambiguate-vocab-by-extra-domain

Conversation

@aldnav
Copy link
Contributor

@aldnav aldnav commented Mar 9, 2026

Why is this change needed?

When importing CSV data with Many2one fields pointing to spp.vocabulary.code, Odoo's built-in db_id_for resolves records by display name.
Because multiple vocabulary codes across different vocabularies can share the same display name (e.g. "Active"), the importer produces a multiple-match warning and resolves arbitrarily instead of picking the correct vocabulary.

Expected

No validation error

Actual

image

There were two vocabularies with the same display name but the resolver fails to differentiate them since the default lookup finds they share the same table.

How was the change implemented?

Two models extended in spp_vocabulary:

ir_fields_converter (new file) — Overrides db_id_for scoped exclusively to spp.vocabulary.code fields. When the field carries a domain, it is evaluated (supporting both list and string forms) and passed as _import_name_search_domain in the search context. Malformed string domains are caught and logged as a warning rather than silently dropped.

vocabulary_code.VocabularyCode — Overrides name_search to merge any _import_name_search_domain from context into the search domain before calling super(). limit defaults to None to let Odoo apply its own default.

New unit tests

Six new tests in spp_vocabulary/tests/test_vocabulary_code.py:

  • test_name_search_without_context_returns_all_matches
  • test_name_search_with_context_domain_scopes_to_vocabulary
  • test_name_search_context_domain_does_not_affect_other_vocabulary
  • test_db_id_for_list_domain_scopes_name_search
  • test_db_id_for_string_domain_scopes_name_search
  • test_db_id_for_no_domain_returns_multiple_match_warning

Unit tests executed by the author

All 6 new tests plus the full spp_vocabulary test suite pass.

How to test manually

  1. Create two vocabularies each containing a code with the same display name (e.g. "Active").
  2. Set up a Many2one field pointing to spp.vocabulary.code with a domain restricting to one vocabulary.
  3. Import a CSV referencing that display name — it should resolve to the correct vocabulary's code with no multiple-match warning.
  4. Remove the domain and re-import — the multiple-match warning should reappear.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue in Odoo's CSV import process where spp.vocabulary.code records with identical display names but belonging to different vocabularies could lead to arbitrary resolution and multiple-match warnings. The solution introduces a robust mechanism to utilize field-specific domains during the import, ensuring that the correct vocabulary code is identified and selected, thereby preventing import errors and improving data integrity.

Highlights

  • CSV Import Disambiguation: Implemented a mechanism to correctly resolve spp.vocabulary.code records during CSV imports when multiple codes share the same display name across different vocabularies, by leveraging field domains.
  • ir.fields.converter Extension: Extended the ir.fields.converter model to override db_id_for, allowing it to pass field domains as context for spp.vocabulary.code lookups.
  • spp.vocabulary.code name_search Override: Modified the name_search method in spp.vocabulary.code to incorporate an _import_name_search_domain from the context, enabling domain-specific searches.
  • Comprehensive Unit Tests: Added six new unit tests to validate the correct behavior of name_search and db_id_for with and without domain contexts, covering various scenarios including string and list domains, and multiple match warnings.
Changelog
  • spp_vocabulary/manifest.py
    • Updated module version from "19.0.2.0.0" to "19.0.2.0.1".
  • spp_vocabulary/models/init.py
    • Imported the new ir_fields_converter module.
  • spp_vocabulary/models/ir_fields_converter.py
    • Added a new file containing the IrFieldsConverter model.
    • Overrode the db_id_for method to inject field domains into the context for spp.vocabulary.code lookups during CSV import.
    • Included logic to safe_eval string domains and log warnings for malformed ones.
  • spp_vocabulary/models/vocabulary_code.py
    • Overrode the name_search method to merge _import_name_search_domain from the context into the search domain.
  • spp_vocabulary/tests/test_vocabulary_code.py
    • Added a helper method _create_shared_display_codes for test setup.
    • Added six new tests to verify name_search and db_id_for behavior with and without context domains, and for handling multiple matches.
Activity
  • The author executed all 6 new unit tests and the full spp_vocabulary test suite, confirming all tests passed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a clever solution to disambiguate vocabulary codes with the same display name during CSV imports by leveraging the field's domain. The override of db_id_for in a new ir.fields.converter model and the corresponding adjustment in name_search are well-implemented. The inclusion of comprehensive unit tests is also a great addition.

My main feedback is to improve the robustness of the error handling and logging within db_id_for to prevent potential crashes within the exception handler itself, especially when model is None as seen in the tests.

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.43%. Comparing base (a3fec68) to head (3426b62).
⚠️ Report is 20 commits behind head on 19.0.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0      #82      +/-   ##
==========================================
+ Coverage   68.28%   68.43%   +0.15%     
==========================================
  Files         557      562       +5     
  Lines       31666    31852     +186     
==========================================
+ Hits        21622    21797     +175     
- Misses      10044    10055      +11     
Flag Coverage Δ
spp_aggregation 80.05% <ø> (ø)
spp_alerts 94.08% <ø> (?)
spp_api_v2 79.96% <ø> (ø)
spp_api_v2_change_request 60.22% <ø> (ø)
spp_api_v2_cycles 71.12% <ø> (ø)
spp_api_v2_data 64.41% <ø> (ø)
spp_api_v2_entitlements 70.19% <ø> (ø)
spp_api_v2_gis 71.52% <ø> (ø)
spp_api_v2_products 66.27% <ø> (ø)
spp_api_v2_service_points 70.94% <ø> (ø)
spp_api_v2_simulation 69.61% <ø> (ø)
spp_api_v2_vocabulary 57.26% <ø> (ø)
spp_base_common 90.26% <ø> (ø)
spp_programs 45.51% <ø> (ø)
spp_security 66.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.
see 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aldnav aldnav force-pushed the fix/disambiguate-vocab-by-extra-domain branch from 3c0f120 to 9330982 Compare March 9, 2026 04:55
…of the same display name

Signed-off-by: Aldrin Navarro <aldrin@newlogic.com>
@aldnav aldnav force-pushed the fix/disambiguate-vocab-by-extra-domain branch from 9330982 to 3426b62 Compare March 9, 2026 05:05
@aldnav aldnav marked this pull request as ready for review March 9, 2026 05:31
@gonzalesedwin1123 gonzalesedwin1123 merged commit 32329d6 into 19.0 Mar 10, 2026
30 checks passed
@gonzalesedwin1123 gonzalesedwin1123 deleted the fix/disambiguate-vocab-by-extra-domain branch March 10, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants